package cn.edu.scau.cmi.chenmiaopeng.controller.compositePattern;
import javafx.stage.Stage;
import cn.edu.scau.cmi.chenmiaopeng.compositePattern.safePattern.*;
import cn.edu.scau.cmi.chenmiaopeng.compositePattern.transparentPattern.*;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
public class ShowInfoController {
	    static Stage stage;
	    static boolean isSafe;  //将其设为静态变量
	    boolean isPersonal;  //该变量判断是否是个人/团队
	    @FXML
	    private Button showInfo;

	    @FXML
	    private ComboBox<?> chooseInstance;

	    @FXML
	    private Button back;

	    @FXML
	    private TextArea textArea;
        
	    
	    private static String nowSelectOrg = null;
	    
	    public static void setSafeType(boolean safe) {
	    	isSafe = safe;
	    }
	    
//	    public void setSelectOrg(String orgName) {
//	    	nowSelectOrg = orgName;
//	    	System.out.println("选择的是："+nowSelectOrg);
//	    }
	    
	    public void setStage(Stage s) {
        stage = s;	
        }
	    
	    @FXML
	    void clickConfirm(ActionEvent event) {
	    	nowSelectOrg = CompositePatternController.getNowSelectOrg();
	    	if(isSafe) {
	    		System.out.println("点击了安全模式！");
//	    		Organization_S originalOrg = CompositePatternController.getOriginalOrganization_S();  //应该从整棵树的根节点开始查询
//	    		CompositePatternController compositeController = new CompositePatternController();
	    		
//	    		String orgnizationName = compositeController.getChooseOrganization();
	    		
	    		if(nowSelectOrg.isEmpty()) {
	    			textArea.setText("您没有选择任何组织，请前往客户端选择组织再查看组织！");
	    		}
	    		else {
//	    			if(nowSelectOrg.contains("orginal organization")) {
//	    				textArea.setText("该组织为根节点！");  //注意 前面还有中文！
//	    			}
	    			//通过组织名去找组织，并返回其对象
		    		//通过对象调用greet()，显示在文本框里
//		            String greet = originalOrg.greet();  //不应该取根节点，而应该取用户选择的组织去greet()
//	    			else{
	    			  //直接进行获取当前点击的节点进行对其子成员的查询
	    				String orgName = CompositePatternController.getNowSelectOrg();
	    				Organization_S resultOrg;
	    				if(orgName.equals("orginal organization")) {
	    					resultOrg = CompositePatternController.getOriginalOrganization_S();
	    				}
	    				else {
	    					InquiryOrganization inqueryOrg = new InquiryOrganization();
		    				resultOrg = inqueryOrg.getOrganization_S(CompositePatternController.getOriginalOrganization_S(),nowSelectOrg);
	    				}
			            textArea.setText(resultOrg.greet());
//	    			}
	    		}
	    	}
	    	else {
//	    		Organization_T originalOrg = CompositePatternController.getOriginalOrganization_T();  //应该从整棵树的根节点开始查询
//	    		CompositePatternController compositeController = new CompositePatternController();
	    		
//	    		String orgnizationName = compositeController.getChooseOrganization();
	    		
	    		if(nowSelectOrg.isEmpty()) {
	    			textArea.setText("您没有选择任何组织，请前往客户端选择组织再查看组织！");
	    		}
	    		else {
//	    			if(nowSelectOrg.contains("orginal organization")) {
//	    				textArea.setText("该组织为根节点！");  //注意 前面还有中文！
//	    			}
	    			//通过组织名去找组织，并返回其对象
		    		//通过对象调用greet()，显示在文本框里
//		            String greet = originalOrg.greet();  //不应该取根节点，而应该取用户选择的组织去greet()
//	    			else{
	    				String orgName = CompositePatternController.getNowSelectOrg();
	    				Organization_T resultOrg;
	    				if(orgName.equals("orginal organization")) {
	    					resultOrg = CompositePatternController.getOriginalOrganization_T();
	    				}
	    				else{
	    					InquiryOrganization inqueryOrg = new InquiryOrganization();
	    					resultOrg = inqueryOrg.getOrganization_T(CompositePatternController.getOriginalOrganization_T(),nowSelectOrg);
	    					//这里没有找到
	    				}
	    				
			            textArea.setText(resultOrg.greet());
//	    			}
	    		}
	    	}
        }

	    @FXML
	    void clickBack(ActionEvent event) {
        stage.close();
	    }
}
